package com.niit.agricstore.controller;

import com.github.pagehelper.PageInfo;
import com.niit.agricstore.entity.Comment;
import com.niit.agricstore.service.CommentService;
import com.niit.agricstore.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    // 获取所有留言列表
    @GetMapping
    public Result getAllComments(@RequestParam int pageNum, @RequestParam int pageSize) {
        PageInfo<Comment >list = commentService.getAllComments(pageNum, pageSize);
        return Result.success(list);
    }

    // 根据留言ID获取留言
    @GetMapping("/getPageById/{comment_user_id}")
    public PageInfo<Comment> getCommentById(@PathVariable Long comment_user_id, @RequestParam int pageNum, @RequestParam int pageSize) {
        return commentService.getCommentByUserId(comment_user_id, pageNum, pageSize);
    }

    // 创建留言
    @PostMapping("/write")
    public String createComment(@RequestBody Comment comment) {
        return commentService.createComment(comment);
    }

    // 更新留言

    // 删除留言
    @DeleteMapping("/delete/{commentId}")
    public int deleteCommentById(@PathVariable int commentId) {
        return commentService.deleteCommentById(commentId);
    }

    // 标记留言为已读/未读
    @PutMapping("/read/{commentId}")
    public int markCommentAsRead(@PathVariable int commentId, @RequestParam int isRead) {
        return commentService.markCommentAsRead(commentId, isRead);
    }

    // 批量标记留言为已读/未读
    @PutMapping("/batch/read")
    public int markCommentBatchAsRead() {
        return commentService.markCommentBatchAsRead();
    }

    // 标记留言为已回复/未回复
    @PutMapping("/reply/{commentId}")
    public int markCommentAsReplied(@PathVariable int  commentId, @RequestParam int isReplied) {
        return commentService.markCommentAsReplied(commentId, isReplied);
    }

}